<!--
  - PaymentLib.php
  - v0.01
  - 2/1/2011
  -
  -	This inserts an analysis into the database.
-->
<?php
	function Pay($sample_key, $payment_mode, $check, $bank, $official_receipt_num,
		$database, $host, $login, $loginpassword, $tablename){ 
		//Create connection. 
		$connect = 
				mysql_connect($host,$login,$loginpassword);	
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		
		//Set-up and execute query.		
		mysql_select_db($database, $connect);		
		$query = "INSERT INTO $tablename (sample_key, payment_mode, 
		check_number, bank, official_receipt_num)
		VALUES ('$sample_key', '$payment_mode', '$check', '$bank', '$official_receipt_num')";
		echo $query;
		$analysis = mysql_query($query);
	
		//Close connection.
		mysql_close($connect);				
		if ($analysis == true) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	function notPaid($sample_key, $database, $host, $login, $loginpassword, $tablename){ 
		//Create connection. 
		$connect = 
				mysql_connect($host,$login,$loginpassword);	
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		
		//Set-up and execute query.		
		mysql_select_db($database, $connect);		
		$query = "SELECT COUNT(*) FROM $tablename WHERE sample_key='$sample_key'";
		//echo $query;
		$analysis = mysql_query($query);
		$count = mysql_fetch_row($analysis);
		//Close connection.
		mysql_close($connect);				
		if ($count[0] > 0) {
			return "disabled='disabled'";
			
		} else {return "";
		}
	}
	
	function paymentInfo($sample_key, $database, $host, $login, $loginpassword, $tablename){ 
		//Create connection. 
		$connect = 
				mysql_connect($host,$login,$loginpassword);	
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		
		//Set-up and execute query.		
		mysql_select_db($database, $connect);		
		$query = "SELECT payment_mode, date, official_receipt_num, bank FROM $tablename WHERE sample_key='$sample_key'";
		$analysis = mysql_query($query);
		$result = mysql_fetch_array($analysis);
		//Close connection.
		mysql_close($connect);				
		return $result;
	}
?>